package conexion.servidor;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.rmi.Naming;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.sql.SQLException;
import java.util.Properties;

import logica.Fachada;
import logica.excepctions.PersistenciaException;


public class MainServidor {

	public static void main(String[] args) throws ClassNotFoundException, SQLException, PersistenciaException, InstantiationException, IllegalAccessException{
		try
		{ 
			Properties p = new Properties();
			Fachada fachada = new Fachada();
		    String nomArch = "configuraciones.properties";
		    p.load(new FileInputStream(nomArch));
		    String ip = p.getProperty("ipServidor");
			String puerto = p.getProperty("port");
			int port = Integer.parseInt(puerto);
			LocateRegistry.createRegistry(port);
			String ruta = "//" + ip + ":" + puerto + "/fachada";
			Naming.rebind(ruta, (Remote) fachada);
			System.out.println("Publicado");
			
		}
		catch (RemoteException e)
		{
			e.printStackTrace();
		}
		catch (FileNotFoundException e)
		{
			e.printStackTrace();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}	
	}

}